package com.hns.can.mainte.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hns.can.common.aop.orgTree.DriverInterfaceAnnotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.entity.BaseEntity;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.mainte.entity.CommEngiStInfoEntity;
import com.hns.can.mainte.vo.EngineRunStatusParamVo;
import com.hns.can.master.entity.BaseCarInfoEntity;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

/**
 * 发动机Service
 * @author:zhangzq
 * @email:
 * @version Revision 2.0.0
 */
@Service
public class EngineManageService extends CommonService {

    @Autowired
    private FillCodeDscValue codeDscValue;

    private void fillInfoValue(List list) throws Exception {
        Map<String,String> map = new HashMap<String,String>();
        map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo1 = new FillParamsVo("lineId", map);
        map = new HashMap<String,String>();
        map.put("organName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo2 = new FillParamsVo("organId", map);
        map = new HashMap<String,String>();
        map.put("licPltNo", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo3 = new FillParamsVo("carId", map);
        map = new HashMap<String,String>();
        map.put("drvName",  GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo4 = new FillParamsVo("drvId", map);
        codeDscValue.fillInfoValue(list,new String[]{GlobalConst.CACHE_KEY_BASE_LINE_INFO,GlobalConst.CACHE_KEY_BASE_ORGAN,GlobalConst.CACHE_KEY_BASE_CAR_INFO,GlobalConst.CACHE_KEY_BASE_DRV_INFO},vo1,vo2,vo3,vo4);
    }

    /**
     * 分页查询发动机运行状态数据
     * @param conditionVo
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @LeftOrgAnnotation()
    @Transactional
    @DriverInterfaceAnnotation()
    public Pagination searchEngineRunStatusPage(EngineRunStatusParamVo conditionVo) throws Exception {
        Pagination page = this.myBatisPage("engineManage.getEngineRunStatusCnt", "engineManage.getEngineRunStatusList", conditionVo, CommEngiStInfoEntity.class);
        List list =  page.getData();
        fillInfoValue(list);
        page.setData(list);
        return page;
    }

    /**
     * 
     * @param conditionVo
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @SuppressWarnings({"unchecked", "rawtypes" })
    @LeftOrgAnnotation()
    @Transactional
    @DriverInterfaceAnnotation()
    public List<BaseEntity> searchEngineRunStatusList(EngineRunStatusParamVo conditionVo) throws Exception {
        List list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("engineManage.getEngineRunStatusList",conditionVo), CommEngiStInfoEntity.class);
        fillInfoValue(list);
        return list;
    }
    
    /**
     * 用于图表
     * @param conditionVo
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @SuppressWarnings({"unchecked", "rawtypes" })
    @LeftOrgAnnotation()
    @Transactional
    @DriverInterfaceAnnotation()
    public List<BaseEntity> getEngineRunStatusListForGraph(EngineRunStatusParamVo conditionVo) throws Exception {
        List list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("engineManage.getEngineRunStatusListForGraph",conditionVo), CommEngiStInfoEntity.class);
        fillInfoValue(list);
        return list;
    }
    
    /**
     * 查询发动机信息
     * @param carId
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    public BaseCarInfoEntity getEngineInfo(String carId)throws Exception{
        @SuppressWarnings("unchecked")
        List<BaseCarInfoEntity> list =PubUtil.convertListMapToObject(this.sqlMapDao.selectList("engineManage.getEngineInfo", carId), BaseCarInfoEntity.class);
        return list.get(0);
    }
}
